package com.czd.support.service;

import com.czd.base.model.Paginate;
import com.czd.base.service.BaseService;
import com.czd.support.common.Configuration;
import com.czd.support.model.Navigation;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 功能说明：头部导航Service
 * 作者：liuxing(2014-12-20 23:15)
 */
@Service
public class NavigationService extends BaseService<Navigation> {

    /**
     * 新增一个头部导航链接配置，返回主键
     * @param parentId
     * @param name
     * @param link
     * @param tank
     * @param leaveCode
     * @param creator
     * @param updator
     * @return
     */
    public int insertAndReturnId(Integer parentId, String name, String link, int tank, String leaveCode, int creator, int updator) {
        Navigation insertBean = new Navigation();
        insertBean.setParentId(parentId);
        insertBean.setName(name);
        insertBean.setLink(link);
        insertBean.setTank(tank);
        insertBean.setLeaveCode(leaveCode);
        insertBean.setCreator(creator);
        insertBean.setUpdator(updator);
        return super.insertAndReturnId(sqlId("insertAndReturnId"), insertBean);
    }

    /**
     * 新增一个头部导航链接配置
     * @param parentId
     * @param name
     * @param link
     * @param tank
     * @param leaveCode
     * @param creator
     * @param updator
     * @return
     */
    public boolean insert(Integer parentId, String name, String link, int tank, String leaveCode, int creator, int updator) {
        return this.insertAndReturnId(parentId, name, link, tank, leaveCode, creator, updator) > 0;
    }

    /**
     * 查询分页
     * @param pageNo
     * @return
     */
    public Paginate queryForPaginate(int pageNo){
        Navigation queryBean = new Navigation();
        queryBean.setPageNo(pageNo);
        queryBean.setPageSize(Configuration.getInstance().getDefault_page_size());
        return this.queryForPaginate(sqlId("queryForPaginate"), sqlId("count"), queryBean);
    }

    /**
     * 根据主键查询链接详细信息
     * @param id
     * @return
     */
    public Navigation findById(int id) {
        return super.selectOneById(sqlId("findById"), id);
    }

    /**
     * 修改操作
     * @param id
     * @param name
     * @param link
     * @param tank
     * @param leaveCode
     * @param updator
     * @return
     */
    public boolean update(int id, Integer parentId, String name, String link,int tank, String leaveCode, int updator) {
        Navigation updateBean = new Navigation();
        updateBean.setId(id);
        updateBean.setParentId(parentId);
        updateBean.setName(name);
        updateBean.setLink(link);
        updateBean.setTank(tank);
        updateBean.setLeaveCode(leaveCode);
        updateBean.setUpdator(updator);
        return super.update(sqlId("update"), updateBean);
    }

    /**
     * 查询一级导航
     * @return
     */
    public List<Navigation> queryParentNavigations() {
        return super.selectList(sqlId("queryParentNavigations"));
    }
}
